package com.zj.sixtyDayChallenge.tree;

/**
 * @program: algorithm
 * @description: 翻转二叉树
 * 226 invert-binary-tree
 * @author: Zhang Bo
 * @create: 2023-02-13 17:44:32
 **/
public class InvertBinaryTree {
    public static void main(String[] args) {
        Solution solution = new InvertBinaryTree().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    class Solution {
        public TreeNode invertTree(TreeNode root) {
            if (root == null) {
                return null;
            }
            this.swap(root);
            this.invertTree(root.left);
            this.invertTree(root.right);

            return root;
        }

        private void swap(TreeNode root) {
            TreeNode temp = root.left;
            root.left = root.right;
            root.right = temp;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}
